package com.xln.furns.dao.impl;

import com.xln.furns.dao.OrderDAO;
import com.xln.furns.entity.Furn;
import com.xln.furns.entity.Order;
import com.xln.furns.entity.OrderItem;

import java.util.List;

public class OrderDAOimpl extends BasicDAO<Order> implements OrderDAO {

    @Override
    public int saveOrder(Order order) {
        String sql = "insert into `order`(`id`,`create_time`,`price`,`status`,`member_id`)\n" +
                "VALUES(?,?,?,?,?) ";
        return update(sql,order.getId(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getMemberId());
    }

    @Override
    public List<Order> queryOrder() {
        String sql = "select `id`,`create_time` `createTime`,`price`,`status`,`member_id` as `memberId` from `order`";


        return queryMulti(sql,Order.class);
    }

    @Override
    public int getTotalRowOrder(Integer memberId) {
        String sql = "SELECT COUNT(*) FROM `order` WHERE `member_id`=?";

        return ((Number) queryScalar(sql,memberId)).intValue();
    }

    @Override
    public List<Order> getPageItem(int memberId,Integer begin, Integer pageSize) {
        String sql = "SELECT `id`,`create_time` `createTime`,`price`,`status`,`member_id` `memberId` \n" +
                "FROM `order` WHERE `member_id`=? ORDER BY `create_time` DESC LIMIT ?,?";
        List<Order> list = queryMulti(sql,Order.class,memberId,begin,pageSize);
        return list;
    }

}
